<template>
    <div class="">
        <el-dialog title="编辑未就业" :visible.sync="dialog" width="40%" :before-close="dialogClose">
            <el-form ref="formData" :model="formData" label-width="100px">
				<el-form-item label="个人信息" prop="userid">
				    <el-select filterable v-model="formData.userid" style="width: 100%;" placeholder="请选择个人信息">
				    	<el-option :label="item.name" :value="item.id" v-for="(item, index) in User"></el-option>
				    </el-select>
				</el-form-item>
				<el-form-item label="姓名" prop="name">
				    <el-input v-model="formData.name" placeholder="请输入姓名"></el-input>
				</el-form-item>
				<el-row>
					<el-col :span="12">
						<el-form-item label="手机号" prop="phone">
						    <el-input v-model="formData.phone" placeholder="请输入手机号"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="身份证号" prop="idcard">
						    <el-input v-model="formData.idcard" placeholder="请输入身份证号"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-form-item label="未就业分类" prop="employno">
					<el-select v-model="formData.employno" style="width: 100%;" placeholder="请选择未就业分类">
						<el-option :label="item" :value="item" v-for="(item, index) in Site.employno"></el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="失业原因" prop="unemployment" v-if="formData.employno=='就业转失业'">
					  <el-checkbox-group v-model="unemployment">
						<el-checkbox v-for="(item, index) in Site.unemployment" :label="item" :key="index">{{item}}</el-checkbox>
					  </el-checkbox-group>
				</el-form-item>
				<el-form-item label="就业意愿" prop="wished">
				    <el-select v-model="formData.wished" style="width: 100%;" placeholder="请选择就业意愿">
				    	<el-option :label="item" :value="item" v-for="(item, index) in Site.wished"></el-option>
				    </el-select>
				</el-form-item>
				<el-form-item label="无意愿原因" prop="nowishreson" v-if="formData.wished=='不愿意就业'">
					<el-checkbox-group v-model="nowishreson">
						<el-checkbox v-for="(item, index) in Site.nowishreson" :label="item" :key="index">{{item}}</el-checkbox>
					</el-checkbox-group>
					<div class="remark">
						<span>备注</span>
						<input v-model="formData.remark" />
					</div>
				</el-form-item>
            	<el-form-item>
            		<el-button @click="dialogClose">取 消</el-button>
            		<el-button type="primary" @click="formSubmit">确 定</el-button>
            	</el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
	import { regionData, codeToText} from 'element-china-area-data'
    export default {
        data() {
			return {
				dialog: false,
				options: regionData,
				User: [],
				Site: [],
				formData: {
					id: 0,
					userid: '', //个人id
					name: '', //姓名
					idcard: '', //身份证
					phone: '', //手机号
					employno: '', //未就业分类
					unemployment: '', //失业原因
					wished: '', //就业意愿
					nowishreson: '', //无意愿原因
				},
				unemployment:[],
				nowishreson:[]
			}
        },
		created() {
		},
		watch: {
			dialog () {
				if(!this.dialog) {
					this.clearFormData()
					this.$emit('getNoEmploy')
				} else {
					this.getUser()
					this.getSite()
				}
			}
		},
        methods: {
			getUser () {
				this.$apiPost('User/getUser').then(res => {
					if(res.code == 1) {
						this.User = res.data
					}
				})
			},
			getSite () {
				if(this.formData.unemployment){
					this.unemployment = this.formData.unemployment.split(',')
				}
				if(this.formData.nowishreson){
					this.nowishreson = this.formData.nowishreson.split(',')
				}
				this.$apiPost('Index/getSiteFile').then(res => {
					if(res.code == 1) {
						this.Site = res.data
					}
				})
			},
			dialogClose(){
				this.$emit('dialogToggle2')
			},
			clearFormData () {
				this.unemployment = []
				this.nowishreson = []
				for(let i in this.formData){
					if(i == 'id') {
						this.formData[i] = 0
					} else {
						this.formData[i] = ''
					}
				}
			},
			// 保存编辑
			formSubmit() {
				if(this.unemployment.length>0){
					this.formData.unemployment = this.unemployment.join(',')
				}
				if(this.nowishreson.length>0){
					this.formData.nowishreson = this.nowishreson.join(',')
				}
				this.$apiPost('Employno/editData', this.formData).then(res => {
					if(res.code == 1) {
						this.$message(res.msg)
						this.dialogClose()
					} else {
						this.$message(res.msg)
					}
				})
			},
        }
    };
</script>
<style scoped>
	.mselect{
		width: 100%;
	}
	.mtdiv{
		margin-top: 10px;
		display: inline-block;
		width: 100%;
	}
	.mtdiv .mtdiv-v{
		float: left;
		width: 50%;
		margin-bottom: 5px;
		display: flex;
		align-items: center;
	}
	.mtdiv .mtdiv-v label{
		float: left;
		margin-right: 10px;
	}
	.mtdiv .el-input{
		float: left;
		width: 80%;
		margin: 5px 0;
	}
	.el-cascader {
		line-height: 32px !important;
	}
	.el-input__inner {
	    height: 32px !important;
	    line-height: 32px !important;
	}
	.el-input__icon {
		line-height: 32px !important;
	}
	.remark{
		display: flex;
		align-items: center;
	}
	.remark input{
		border: 0;
		border-bottom: 1px solid #333;
		padding: 8px 10px;
		outline:none;
	}
</style>
